﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Threading;
using System.Collections;

namespace TestMap2
{
    public partial class Form1 : Form
    {
        GpsMapImage mapa;
        ArrayList a = new ArrayList();
        ArrayList b = new ArrayList();

        public Form1()
        {
            InitializeComponent();
            a.Add("48.70689");
            b.Add("21.25141");
            a.Add("48.71011");
            b.Add("21.24988");
            a.Add("48.71049");
            b.Add("21.24868");
            a.Add("48.71101");
            b.Add("21.24807");
            a.Add("48.71651");
            b.Add("21.25098");
            a.Add("48.71727");
            b.Add("21.25098");



            //mapa = new GpsMapImage(new GpsPoint(48.706847, 21.251212), new GpsPoint(48.717388, 21.250935), pictureBox_map.Width, pictureBox_map.Height);
            mapa = new GpsMapImage(new GpsPoint(48.713856, 21.248202), new GpsPoint(48.716217, 21.25464), pictureBox_map.Width, pictureBox_map.Height);
           
            
            if (mapa.ok)
            {
                pictureBox_map.Image = mapa.image;
            }
            else MessageBox.Show(mapa.error);
            if (true)
            {
                //Point tmpPoint = mapa.latlonToPixelsFromCenter(new GpsPoint(48.713817, 21.247859));
                Point tmpPoint = mapa.degreesToPixelsFromUpperLeft(new GpsPoint(48.70689, 21.25141));
                //radioButton1.Location = tmpPoint;
                textBox1.Text = tmpPoint.X + ", " + tmpPoint.Y;
            }
        }

        int i = -1;
        private void menuItem2_Click(object sender, EventArgs e)
        {
            i++;

            double pixelX = Double.Parse((string)b[i]);
            double pixelY = Double.Parse((string)a[i]);
            if (i == 5) i = -1;
            Point tmpPoint = mapa.degreesToPixelsFromUpperLeft(new GpsPoint(pixelY, pixelX));
            tmpPoint.X -= (int)Math.Round((double)radioButton1.Size.Width / 2);
            tmpPoint.Y -= (int)Math.Round((double)radioButton1.Size.Height / 2);
            radioButton1.Location = tmpPoint;
            textBox1.Text = tmpPoint.X + ", " + tmpPoint.Y;
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            ThreadStart thread = () =>
            {
                //mapImage = new GpsMapImage(point, finishPoint, pictureBoxMap.Size.Width, pictureBoxMap.Size.Height);
                textBox1.Visible = false;
            };
            thread.Invoke();
        }
    }
}